package com.fzkj.thread.async;

import java.util.Timer;
import java.util.TimerTask;

/**
 * 测试变量同步
 */
public class MyTimerTask extends TimerTask {

    public static boolean run = true;
    private Timer timer;
    public MyTimerTask(Timer timer){
        this.timer = timer;
    }

    @Override
    public void run() {
        if (run){
            System.out.println("线程执行 ： " + run);
//            System.gc(); // 释放timer，实际项目中不能这么使用
            this.timer.cancel();
        }
    }
}
